package com.eip.zd.controller;

import com.eip.zd.common.Result;
import com.eip.zd.entity.Credit;
import com.eip.zd.service.CreditService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/credit")
public class CreditController {
    @Resource
    private CreditService creditService;

    @GetMapping("/getCreditList")
    public Result getCreditList(@RequestParam(required = false) String keyword) {
        List<Credit> creditList = creditService.getCreditList(keyword);
        return Result.success(creditList);
    }
    @GetMapping("/getHisCreditList/{custId}")
    public Result getHisCreditList(@PathVariable String custId) {
        List<Credit> creditList = creditService.getHisCreditList(custId);
        return Result.success(creditList);
    }
    @GetMapping("/getCreditByCustId/{custId}")
    public Result getCreditByCustId(@PathVariable String custId) {
        Credit credit = creditService.getCreditByCustId(custId);
        return Result.success(credit);
    }
    @PostMapping("/add")
    public Result addCredit(@RequestBody Credit credit) {
        creditService.add(credit);
        return Result.success();
    }
    @PostMapping("/update")
    public Result updateCredit(@RequestBody Credit credit) {
        creditService.update(credit);
        return Result.success();
    }
    @PostMapping("/remove/{id}")
    public Result removeCredit(@PathVariable Long id) {
        creditService.remove(id);
        return Result.success();
    }
    @PostMapping("/ifUse/{id}")
    public Result ifUse(@PathVariable Long id) {
        creditService.ifUse(id);
        return Result.success();
    }
}
